import React, { useContext } from 'react'
import myContext from '../usecontext.js'
import { Table } from 'antd';


export default function Memory(props) {
  const info = useContext(myContext);

  const serve = info.info

  // console.log(serve);
  const columns = [
    {
      dataIndex: 'name',
      key: 'path',
    },
    {
      dataIndex: 'sys',
      key: 'value',
    },
    {
      dataIndex: 'type',
      key: 'value',
    },
    {
      dataIndex: 'stand',
      key: 'value',
    },
    {
      dataIndex: 'port',
      key: 'value',
    },
    {
      dataIndex: 'count',
      key: 'value',
    },
    {
      dataIndex: 'counts',
      key: 'value',
    },
    {
      dataIndex: 'kps',
      key: 'value',
    }
  ]
  const data = [
    {
      key: '1',
      name: 'Redis版本',
      sys: serve.redis_version,
      type: '运行模式',
      stand: '单机',
      port: '端口',
      count: serve.tcp_port,
      counts: '客户端数',
      kps: serve.connected_clients
    },
    {
      key: '2',
      name: '运行时间(天)',
      sys: serve.uptime_in_days,
      type: '使用内存',
      stand: serve.used_memory_human,
      port: '使用CPU',
      count: serve.used_cpu_sys_children,
      counts: '内存配置',
      kps: serve.config_file
    },
    {
      key: '3',
      name: 'AOF是否开启',
      sys: serve.aof_enabled === '0' ? '否' : '是',
      type: 'RDB是否成功',
      stand: serve.rdb_last_bgsave_status,
      port: 'Key数量',
      count: info.dbSize,
      counts: '网络入口/出口',
      kps: serve.instantaneous_input_kbps + 'kps' + '/' + serve.instantaneous_output_kbps + 'kps'
    }
  ]
  return (
    <Table bordered={true} showHeader={false} pagination={false} columns={columns} dataSource={data} />
  )
}
